define([
  'jquery',
  'utils/Logger',
  'routers/Router',
  'models/Subscriber',
  'collections/Subscribers',
  'views/subscribers/SubscribersList',
  'views/subscribers/SubscriberDetail'
], function($, Logger, Router, Subscriber, Subscribers, SubscriberList, SubscriberDetail){
  var SubscriberRouter = Router.extend({
    routes: {
      "":                    "subscribers", 
      "!/subscribers":       "subscribers",
      "!/subscriber/:id":    "detail",
      "!/subscribers/add":   "add"
    },

    initialize: function(options) {
      Router.prototype.initialize.call(this, options);
      // $(".loading").ajaxStart(function() {
      //   $(this).show();
      // });

      // $(".stop").ajaxStart(function() {
      //   $(this).show();
      // });

    },
    
    subscribers: function() {
      Logger.debug("Soy Subscribers index");
      //batzen.state.clearMessages();
      var subscribers = new Subscribers();
      subscribers.pagination.setLimit(5);
      var subscribersView = new SubscriberList({collection: subscribers, messages: this.messages});
      $("#app").html(subscribersView.render().el);

      subscribers.fetch();
    },

    detail: function(id) {
      //batzen.state.clearMessages();
      Logger.debug("Detail of susbcriber with id: " + id);
      var subscriber = new Subscriber({id: id});
      var view = new SubscriberDetail({model: subscriber});
      $("#app").html(view.render().el);

      subscriber.fetch();
    },
    
    add: function() {
      Logger.debug("Soy Subscribers add");
      var subscriber = new Subscriber();      
    }  
  });

  return SubscriberRouter;
});
